package com.he.architecture.controller;


import com.he.architecture.common.controller.LogicController;
import com.he.architecture.dao.UserDao;
import com.he.architecture.dto.EntityDtos.UserResponseDto;
import com.he.architecture.dto.ResponseResult;
import com.he.architecture.dto.UserRequestDto;
import com.he.architecture.entity.User;
import com.he.architecture.service.UserService;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController extends LogicController<UserService, UserDao, User,Long> {
    public UserController(@Autowired UserService service){
        super(service);
    }
    @Resource
    ModelMapper modelMapper;


    /**
     * 登录
     */
    @PostMapping("/login")
    public ResponseResult login(@RequestBody UserRequestDto userRequestDto){
        User user= getService().login(userRequestDto.getUsername(),userRequestDto.getPassword());
        Map<String,Object> map=new HashMap<>();
        map.put("user",modelMapper.map(user, UserResponseDto.class));
        return new ResponseResult(200,map);
    }
}
